<template>
	<view>
		<u-sticky>
			<view class="bg-white u-p-b-20">
				<u-tabs :list="tabs" :activeStyle="activeStyle" lineColor="#FF5B00" :scrollable="false" @change="click()"></u-tabs>
			</view>
		</u-sticky>
		<block v-for="(item,k) in couponInfoList" :key="k" v-if="index==0">
			<view class="juan flex align-center">
				<view class="u-p-l-20 u-p-t-32 u-p-b-32" style="width: 500rpx;">
					<view class="text-bold text-bold ">{{item.title}}</view>
					<view class="u-font-24 u-m-t-10 text999">{{item.outTime}}到期</view>
					<view class="flex align-center u-m-t-10">
						<view class="u-font-24 text999 u-m-r-10">{{item.type==0?'洗衣券':'商城券'}}</view>
						<!-- <u-icon name="arrow-down-fill" size="10" color="#999999"></u-icon> -->
					</view>
				</view>
				<view class="flex align-center justify-center flex-direction" style="width: 190rpx;height: 100%;">
					<view class="">
						<text class="price " :class="item.userInfoId==userInfoId?'text-expire':''">{{item.amount}}</text>
						<text class="u-font-24" :class="item.userInfoId==userInfoId?'text-expire':''" style="color: #FF2E3F;">元</text>
					</view>
					<view class="u-font-22" :class="item.userInfoId==userInfoId?'text-expire':''" style="color: #FF2E3F;">满{{item.fullSub}}元可用</view>
					<view class="btn" :class="item.userInfoId==userInfoId?'btn-bg':''" @tap="handleUserGetCouponInfo(item.id)">
						{{item.userInfoId==userInfoId?"已领取":"领取"}}
						</view>
				</view>
			</view>
		</block>
		
		<block v-for="(item,k) in userCouponInfoList" :key="k" v-if="index!=0">
			<view class="juan flex align-center">
				<view class="u-p-l-20 u-p-t-32 u-p-b-32" style="width: 500rpx;">
					<view class="text-bold text-bold ">{{item.couponInfo.title}}</view>
					<view class="u-font-24 u-m-t-10 text999">{{item.outTime}}到期</view>
					<view class="flex align-center u-m-t-10">
						<view class="u-font-24 text999 u-m-r-10">{{item.couponInfo.type==0?'洗衣券':'商城券'}}</view>
						<!-- <u-icon name="arrow-down-fill" size="10" color="#999999"></u-icon> -->
					</view>
				</view>
				<view class="flex align-center justify-center flex-direction" style="width: 190rpx;height: 100%;">
					<view class="">
						<text class="price " :class="item.status==0?'':'text-expire'">{{item.couponInfo.amount}}</text>
						<text class="u-font-24" :class="item.status==0?'':'text-expire'" style="color: #FF2E3F;">元</text>
					</view>
					<view class="u-font-22" :class="item.status==0?'':'text-expire'" style="color: #FF2E3F;">满{{item.couponInfo.fullSub}}元可用</view>
					
					<view class="btn" :class="item.status==0&&index==1?'':'btn-bg'" v-if="index==1" @click="handleGoCategory()">
						   使用
					</view>
					
					<view class="btn" v-if="index==2">
						   已使用
					</view>
					<view class="btn" v-if="index==3">
						   已过期
					</view>
				</view>
			</view>
		</block>

	</view>
</template>

<script>
	import {
		getCouponInfoList,getUserCouponInfoList,userGetCouponInfo
	} from '@/common/api/api.js'
	export default {
		data() {
			return {
				activeStyle: {
					color: '#FF5B00',
				},
				tabs: [{
					name: '未领取',
					status:"-1"
				}, {
					name: '未使用',
					status:"0"
				}, {
					name: '已使用',
					status:"1"
				}, {
					name: '已到期',
					status:"2"
				}],
				couponInfoList:[],// 优惠券列表
				userInfoId:'',
				tabItem:{index:0,name:''},
				userCouponInfoList:[],// 用户优惠券
				index:0,
			}
		},
		onLoad(){
			this.handleGetCouponInfoList();
			this.userInfoId=this.$store.state.$token;
		},
		methods: {
			click(item) {
				console.log('item', item);
				this.tabItem=item;
				// this.index=item.index;
				if(item.index==0){
					this.handleGetCouponInfoList();
				}else{
					this.handleGetUserCouponInfoList(item);
				}
				
			},
			// 获取用户未领的优惠券信息
			handleGetCouponInfoList(){
				let that=this;
				getCouponInfoList({status:'1'}).then(res=>{
					that.couponInfoList=res.data.list;
					this.index=0;
				})
			},
			// 获取用户优惠券
			handleGetUserCouponInfoList(item){
				let that=this;
				getUserCouponInfoList({userInfoId:that.$store.state.$token,status:item.status}).then(res=>{
					that.userCouponInfoList=res.data.list;
				})
				that.index=item.index;
				console.log("123213123",that.userCouponInfoList,that.index);
			},
			// 用户领取优惠券
			handleUserGetCouponInfo(couponInfoId){
				var params={couponId:couponInfoId,userInfoId:this.$store.state.$token};
				userGetCouponInfo(params).then(res=>{
					if(res.code==200){
						
					}
				})
			},// 使用优惠券
			handleGoCategory(){
				this.$u.route('/pages/index/category/category');
			}
			
		}
	}
</script>

<style lang="scss">
	.juan {
		margin-top: 20rpx;
		margin-left: 32rpx;
		margin-right: 32rpx;
		width: 686rpx;
		height: 186rpx;
		background: #FFFFFF;
		border-radius: 8rpx;
		background-image: url('/static/personal/coupon-juan.png');
		background-size: 100% 100%;

		.price {
			font-size: 52rpx;
			font-family: D-DIN DIN-Bold, D-DIN DIN;
			font-weight: bold;
			color: #FF2E3F;
		}

		.btn {
			width: 120rpx;
			height: 48rpx;
			line-height: 48rpx;
			text-align: center;
			color: #fff;
			background: linear-gradient(90deg, #FE5C32 0%, #FF2F40 100%);
			border-radius: 30rpx;
			margin-top: 6rpx;
		}
	}

	.rlus {
		width: 686rpx;
		height: 160rpx;
		background: #FAFAFA;
		margin-left: 32rpx;
		margin-right: 32rpx;
	}

	.text-expire {
		color: #D3D6E6 !important;
	}

	.btn-bg {
		background: #D3D6E6 !important;
		color: #fff;
	}
</style>